﻿using Capture.Model;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Capture.DAL
{
    public class DataCaptureDAL
    {
        public static string _dataCapture = "DataCapture";
        /// <summary>
        /// 添加单条DataCapture
        /// </summary>
        public bool CreateDataCapture(DataCapture model)
        {
            using (MongoHelp _dal = new MongoHelp { Table = _dataCapture })
            { _dal.Insert<DataCapture>(model); }
            return true;
        }
        /// <summary>
        /// 获取最大Id
        /// </summary>
        /// <returns></returns>
        public int GetMaxId()
        {
            using (MongoHelp _dal = new MongoHelp { Table = _dataCapture })
            {
                return 1;
            }
        }
        /// <summary>
        /// 获取单条数据
        /// </summary>
        public DataCapture GetDataCapture(String name)
        {
            var _filter = Builders<DataCapture>.Filter.Eq("Name", name);
            using (MongoHelp _dal = new MongoHelp { Table = _dataCapture })
            { return _dal.GetOne<DataCapture>(_filter); }
        }
        /// <summary>
        /// 获取一组树
        /// </summary>
        public List<DataCapture> GetDataCaptureList(int eid)
        {
            var _filter = Builders<DataCapture>.Filter.Eq("Eid", eid);
            using (MongoHelp _dal = new MongoHelp { Table = _dataCapture })
            { return _dal.GetMany<DataCapture>(_filter); }
        }
        /// <summary>
        /// 获取条数
        /// </summary>
        public long GetAdvCount()
        {
            using (MongoHelp _dal = new MongoHelp { Table = _dataCapture })
            {
                var _filter = Builders<DataCapture>.Filter.Ne("_id", "");
                return _dal.GetCount<DataCapture>(_filter);
            }
        }
    }
}
